@extends('master/master_index')

@section('title')
    <title>个人中心</title>
@endsection

@section('css')
    <link rel="stylesheet" type="text/css" href="{{asset('home/css/Topic_UserCenter.css')}}">
    <style>

        html, body {
            margin: 0;
            padding: 0;
        }

        .wrap-dialog {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            font-size: 16px;
            text-align: center;
            background-color: rgba(0, 0, 0, .4);
            z-index: 999;
        }

        .dialog {
            position: relative;
            margin: 15% auto;
            width: 300px;
            background-color: #FFFFFF;

        }

        .dialog .dialog-header {
            height: 20px;
            padding: 10px;
            background-color: lightskyblue;
        }

        .dialog .dialog-body {
            height: 30px;
            padding: 20px;
        }

        .dialog .dialog-footer {
            padding: 12px;
            background-color: whitesmoke;
        }

        .btn {
            width: 70px;
            padding: 2px;
        }

        .hide {
            display: none;
        }

        .ml50 {
            margin-left: 50px;
        }
    </style>
@endsection

@section('content')
    <div class="con_content">
        <div class="big_table">
            <div class="small_table">
                <div class="table_top">
                    <div class="img_header"><img src="{{asset($user->profile['avatar'])}}"></div>
                    <ul class="table_t_l">
                        <li class="username">{{$user['username']}}</li>
                        @if($user->profile->gender==1)
                            <li class="li_gender"><img class="gender_img gender3" src="{{asset('home/img/man.png')}}">
                            </li>
                        @elseif($user->profile->gender==0)
                            <li class="li_gender"><img class="gender_img_woman gender2"
                                                       src="{{asset('home/img/woman.png')}}"></li>
                        @endif
                        <li>第 <span>{{$user['id']}}</span> 名成员</li>
                        <li>注册于 <span>{{$user['created_at']->diffForHumans()}}</span></li>
                        <li>活跃于 <span>{{$user['updated_at']->diffForHumans()}}</span></li>
                    </ul>
                </div>
                <div class="table_content">
                    <ul>
                        <li class="Ta_li_follower">
                            <p>{{count($user->another)}}</p>
                            <span>关注者</span>
                        </li>
                        <li class="Ta_li_topic">
                            <p>{{count($user->topic)}}</p>
                            <span>文章</span>
                        </li>
                        <li class="Ta_li_reply">
                            <p>{{count($user->reply)}}</p>
                            <span>评论</span>
                        </li>
                    </ul>
                </div>
                <div class="table_foot">
                    <a href="{{url('profile_update')}}" class="profile_update_a">
                        <i class="Hui-iconfont">&#xe683;</i>编辑个人资料</a>
                </div>
            </div>
        </div>
        <div class="con_left_wrap">
            <div class="con_left">
                <div class="le_top">专栏文章</div>
                <div id="none">
                    <a href="{{url('topic_post')}}" class="topic_post user_center_a"><i class="Hui-iconfont">
                            &#xe6df;</i>发表文章</a>
                </div>
            </div>
            <div class="con_left">
                <div class="le_top">最近文章</div>
                @if(count($user->topic)>0)
                    <div class="le_foot">
                        <ul>
                            @foreach($user->topic as $p)
                                <li>
                                    <a href="{{url('topic')}}/topics={{$p['id']}}" class="a1">{{$p->title}}</a>
                                    <span class="s1">
                                        @foreach($p->tags as $g)
                                            <span class="e">{{$g->tag_name}}</span>
                                        @endforeach
                                        <p>{{count($p->replies)}}回复</p>
                                        <p>{{$p['created_at']->diffForHumans()}}</p>
                                    </span><br/>
                                    <a class="update_a" href="{{url('update_topic_view')}}/topic={{$p->id}}"><i
                                                class="Hui-iconfont" style="color:#a2d3e5;">&#xe72a;</i></a>
                                    <i class="Hui-iconfont s3" style="color:#e56362;">&#xe609;<input type="text"
                                                                                                     style="display: none;"
                                                                                                     value="{{$p->id}}"></i>
                                </li>
                            @endforeach
                        </ul>
                    </div>
                @else
                    <div id="none">暂无评论！</div>
                @endif
            </div>
            <div class="con_left">
                <div class="le_top">最近评论</div>
                @if(count($user->reply)>0)
                    <div class="le_foot2">
                        <ul>
                            @foreach($user->reply as $p)
                                <li class="reply_li">
                                    <a href="{{url('topic')}}/topics={{$p->topic['id']}}"
                                       class=" a2">{{$p->topic->title}}</a><span> at {{$p['created_at']->diffForHumans()}}</span><br/>
                                    <p class="reply_i">{{$p['content']}}</p>
                                    <i class="Hui-iconfont s4" style="color:#e56362">&#xe609;
                                        <input type="text" style="display: none;" value="{{$p->id}}">
                                    </i>
                                </li>
                            @endforeach
                        </ul>
                    </div>
                @else
                    <div id="none">暂无评论！</div>
                @endif
            </div>
        </div>
        <div class="big_table_next">
            <input class="hide_input_user_id" type="hidden" value="{{$user->id}}">
            <ul>
                <li class="Ta Ta_topic"><i class="Hui-iconfont i_ta">&#xe652;</i> Ta 发布的文章</li>
                <li class="Ta Ta_reply"><i class="Hui-iconfont i_ta">&#xe622;</i> Ta 发表的评论</li>
                <li class="Ta Ta_follow"><i class="Hui-iconfont i_ta">&#xe650;</i> Ta 关注的用户</li>
                <li class="Ta Ta_vote"><i class="Hui-iconfont i_ta">&#xe66d;</i> Ta 点赞的文章</li>
            </ul>
        </div>
        <div class="wrap-dialog hide">
            <div class="dialog">
                <div class="dialog-header">
                    <span class="dialog-title">删除确认</span>
                </div>
                <div class="dialog-body">
                    <span class="dialog-message"></span>
                </div>
                <div class="dialog-footer">
                    <input type="button" class="btn" id="confirm" value="确认"/>
                    <input type="button" class="btn ml50" id="cancel" value="取消"/>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script type="application/javascript">
        var followerUrl = '{{url('Ta_follower')}}';
        var topicUrl = '{{url('Ta_topic')}}';
        var replyUrl = '{{url('Ta_reply')}}';
        var followUrl = '{{url('Ta_follow')}}';
        var voteUrl = '{{url('Ta_vote')}}';
        $('.s4').click(function () {
            var self = this;
            $('.dialog-message').html('确认删除此评论？')
            $('.wrap-dialog').fadeIn();
            $('#cancel').click(function () {
                $('.wrap-dialog').slideUp();
            })
            $('#confirm').click(function () {
                $('.wrap-dialog').hide();
                var reply_id = $(self).find('input').val();
                $.ajax({
                    type: 'POST',
                    url: '{{url('delete_reply')}}',
                    data: {reply_id: reply_id},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function () {
                        $(self).parents('li').slideUp(300, function () {
                            $(self).remove();
                        });
                    },
                    error: function () {
                        alert('Ajax error!')
                    }
                });
            });
        });


        $('.s3').click(function () {
            var self = this;
            $('.dialog-message').html('确认删除此文章？')
            $('.wrap-dialog').fadeIn();
            $('#cancel').click(function () {
                $('.wrap-dialog').slideUp();
            });
            $('#confirm').click(function () {
                $('.wrap-dialog').hide();
                var topic_id = $(self).find('input').val();
                $.ajax({
                    type: 'POST',
                    url: '{{url('delete_topic')}}',
                    data: {topic_id: topic_id},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function () {
                        $(self).parents('li').slideUp(300, function () {
                            $(this).remove();
                        });
                    },
                    error: function () {
                        alert('Ajax error!')
                    }
                });
            });
        });

    </script>
@endsection
